package com.yinhanshi.s3test.sign;

import com.yinhanshi.s3test.bean.UploadPieceResponse;
import com.yinhanshi.s3test.http.ApiRetrofit;

import java.util.HashMap;
import java.util.Map;

import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;
import okhttp3.MultipartBody;

/**
 * 标题：通过安全令牌方式，对文件进行上传
 * 只承担整个文件（分片）上传，不考虑分片逻辑
 * 作者：yinhanshi .
 */
public class SignUploader {

    private boolean userInterrupted = false;
    private boolean userAborted = false;
    private UploadProgressListener uploadProgressListener;
    private static SignUploader instance;

    public static SignUploader getInstance() {
        return instance;
    }

    /**
     * 初始化
     */
    public SignUploader() {

    }

    /**
     * 开始文件上传
     */
    public void start(){
        Map<String,String> headers = new HashMap<>();
        MultipartBody.Part part = null;

        ApiRetrofit.getInstance().uploadFile(headers,part)
                .subscribe(new Observer<UploadPieceResponse>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(UploadPieceResponse uploadPieceResponse) {

                    }

                    @Override
                    public void onError(Throwable e) {
                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }

    /**
     * 暂停上传操作
     */
    public void InterruptUpload(){

    }

    /**
     * 取消上传操作
     */
    public void cancelUpload(){

    }

    /**
     * 获取文件上传进度
     * @param fileKey 文件标示
     */
    public void getFileUploadedPercent(String fileKey){

    }

    /**
     * 获取文件上传长度
     * @param fileKey 文件标示
     */
    public void getFileUploadedSize(String fileKey){

    }

    /**
     * 进度回调
     * @param progressListener UploadProgressListener
     */
    public void setProgressListener(UploadProgressListener progressListener) {
        this.uploadProgressListener = progressListener;
    }

    public interface UploadProgressListener {
        public void progressChanged(long bytesUploaded, int percentUploaded);
    }

}
